import { defaultStatusMap } from '@/configs/defaultStatus/defaultStatusMap.ts'
import { defineStore } from 'pinia'
import { MaterialComDesType, MaterialComType } from '@/constants'
import {
  addOptionsStatus,
  addStringArrStatus,
  removeOptionsArrStatus,
  setCurrentStatus,
  setOptionsisUserStatus,
  setPicImageStatus,
  setTextPropsStatus,
} from '@/store/actions.ts'
import type { EditorComps } from '@/types'
import { updateInitStatusBeforeAdd } from '@/utils'
const initMaterialComArr = [
  {
    key: MaterialComDesType.PersonalAddress,
    com: defaultStatusMap[MaterialComType.TextInput](),
  },
  {
    key: MaterialComDesType.PersonalEmail,
    com: defaultStatusMap[MaterialComType.TextInput](),
  },
  {
    key: MaterialComDesType.PersonalPhoneNumber,
    com: defaultStatusMap[MaterialComType.TextInput](),
  },
  {
    key: MaterialComDesType.PersonalQQ,
    com: defaultStatusMap[MaterialComType.TextInput](),
  },
  {
    key: MaterialComDesType.PersonalWechat,
    com: defaultStatusMap[MaterialComType.TextInput](),
  },
];

let initMaterialCom:{[key:string]:EditorComps } = {};
initMaterialComArr.forEach(item => {
  const editorComs = item.com;
  updateInitStatusBeforeAdd(editorComs,item.key);
  initMaterialCom[item.key] = editorComs;
})

console.log('initMaterialCom',initMaterialCom)

export const useMaterialStore = defineStore('material', {
  state: () => {
    return {
      currentMaterialCom: MaterialComDesType.SingleSelect,
      // 记录所有的业务组件
      comS: {
        [MaterialComDesType.SingleSelect]: defaultStatusMap[MaterialComType.SingleSelect](),
        [MaterialComDesType.MultiSelect]: defaultStatusMap[MaterialComType.MultiSelect](),
        [MaterialComDesType.DropDownSelect]: defaultStatusMap[MaterialComType.DropDownSelect](),
        // 单选题图片选择
        [MaterialComDesType.SingleImageSelect]:
          defaultStatusMap[MaterialComType.SingleImageSelect](),
        [MaterialComDesType.TextInput]: defaultStatusMap[MaterialComType.TextInput](),
        // 评价/打分
        [MaterialComDesType.RateScore]: defaultStatusMap[MaterialComType.RateStore](),
        // 时间选择器
        [MaterialComDesType.DateTime]: defaultStatusMap[MaterialComType.DateTime](),
        // 备注
        [MaterialComDesType.TextNote] : defaultStatusMap[MaterialComType.TextNote](),
        // 手机号码
        [MaterialComDesType.PersonalPhoneNumber] : initMaterialCom[MaterialComDesType.PersonalPhoneNumber],
        [MaterialComDesType.PersonalAddress] : initMaterialCom[MaterialComDesType.PersonalAddress],
        [MaterialComDesType.PersonalEmail] : initMaterialCom[MaterialComDesType.PersonalEmail],
        [MaterialComDesType.PersonalQQ] : initMaterialCom[MaterialComDesType.PersonalQQ],
        [MaterialComDesType.PersonalWechat] : initMaterialCom[MaterialComDesType.PersonalWechat],

      },
    }
  },
  actions: {
    setTextPropsStatus,
    addStringArrStatus,
    removeOptionsArrStatus,
    setCurrentStatus,
    setPicImageStatus,
    addOptionsStatus,
    setOptionsisUserStatus,
    setCurrentMaterialCom(currentMaterialCom: MaterialComDesType) {
      this.currentMaterialCom = currentMaterialCom
    },
  },
})
